<?php

include_once 'curl.php';
$appid="wx465740a9cd284533"; //你的appid
$appsecret = "c62f2ff49e5ad74ecf5ac7adef5e7253";  //你的appsecret
$xmldata =file_get_contents("php://input");//$_POST["code"];
//实例化redis
$redis = new Redis();
//连接
$redis->connect('127.0.0.1', 6379); 
$array = json_decode($xmldata,true);
$code = $array["code"];
// $session3rd = $array->session3rd;
// if(!empty($session3rd)){
// 	$session_key = $redis->get($session3rd);
// 	if(isset($session_key)){
// 		echo $session3rd; 
// 		exit; 
// 	} 

// }
// else{
	$url ="https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$appsecret}&js_code={$code}&grant_type=authorization_code";

	$result = json_encode(toCurl($url,"GET",[],true));


//生成第三方3rd_session
	$session3rd  = null;
	$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
	$max = strlen($strPol)-1;
	for($i=0;$i<16;$i++){ 

		$session3rd .=$strPol[rand(0,$max)];
	}

	$redis->set($session3rd, $result,7200);
	$redis->close();
	unset($redis); 

	// }
echo $session3rd;

	


